package com.longrise.android.byjk.plugins.tabthird.personal;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;

import com.longrise.android.byjk.R;
import com.longrise.common.base.BaseActivity2;
import com.longrise.common.utils.AppUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/3/6.
 * 更换背景---高级版
 */

public class ChangeSeniorWallActivity extends BaseActivity2<ChangeSeniorWallPresenter> implements ChangeSeniorWallContract.View{

    private TabLayout mTb;
    private ViewPager mVp;
    private List<BackGroundWallBean> mParentBeanList = new ArrayList<>();

    @Override
    public int getContentViewId(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_change_senior_wall;
    }

    @Override
    public void initView() {
        mTb = (TabLayout)findViewById(R.id.change_wall_tab);
        mVp = (ViewPager)findViewById(R.id.change_wall_vp);
        setToolbarTitle(AppUtil.getString(R.string.change_background));
        EventBus.getDefault().register(this);
    }

    @Override
    public void onToolbarBackClick() {
        finish();
    }

    @Override
    public void initAdapter(List<BackGroundWallBean> parentList) {
        mParentBeanList.clear();
        mParentBeanList.addAll(parentList);

        ChangeSeniorPagerAdapter pagerAdapter = new ChangeSeniorPagerAdapter(getSupportFragmentManager());
        pagerAdapter.setData(mParentBeanList);
        mVp.setAdapter(pagerAdapter);
        mTb.setupWithViewPager(mVp);

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void changeSkin(ChangeWallEvent event) {
        boolean refresh = event.isRefresh();
        //用于刷新
        if(refresh){
            mPresenter.getSeniorWallData();
        }
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }


}
